﻿using C1.WPF.FlexGrid;
using Model.Modules;
using SteelDetection.UIControl;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ViewModel;
using ViewModel.VM;

namespace SteelDetection
{
    /// <summary>
    /// WindowReviewDefect.xaml 的交互逻辑
    /// </summary>
    public partial class PageReviewDefect : Page
    {
        public PageReviewDefect()
        {
            InitializeComponent();
            imggrid.Loaded += (s, e) => {
                imggrid.ColumnHeaders.Rows[0].Height = 50;
                var converter = new ColumnValueConverter();
                converter.SetSource(CameraTypes.GetInstance(),"id","name");
                imggrid.Columns[1].ValueConverter = converter;
            };
            Loaded += PageReviewDefect_Loaded;
        }

        private void PageReviewDefect_Loaded(object sender, RoutedEventArgs e)
        {
            (this.DataContext as VM_PageReviewDefect).RequestShowDialog += (s, ee) =>
            {
                DefectTypeDlg dlg = new DefectTypeDlg();
                var dlgresult = dlg.ShowDialog();
                if ((bool)dlgresult == true)
                {

                    ee.Callback(dlg.Dtype);
                }
            };
            Loaded -= PageReviewDefect_Loaded;
        }

        private void C1ComboBox_SelectedItemChanged(object sender, C1.WPF.PropertyChangedEventArgs<object> e)
        {
            typebtn.Focus();
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void C1FlexGrid_ItemsSourceChanged(object sender, EventArgs e)
        {
            if((sender as C1FlexGrid).Rows.Count>0)
                (sender as C1FlexGrid).SelectedIndex = 0;
        }

        private void C1FlexGrid_SelectedItemChanged(object sender, EventArgs e)
        {
            
            (sender as C1FlexGrid).ScrollIntoView((sender as C1FlexGrid).Selection.Row,0);
        }
        private void imagedefectgrid_SelectionChanged(object sender, CellRangeEventArgs e)
        {
            //用于更新多选选中的图像缺陷
            if (this.DataContext != null)
                (this.DataContext as VM_PageReviewDefect).SelectedImageDefects = new ObservableCollection<image_defect>(imagedefectgrid.SelectedItems.Cast<image_defect>());
        }
    }
}
